import argparse
import numpy
import matplotlib.pyplot as plt

parser = argparse.ArgumentParser(description='view npy file. that is a spectrum.')
parser.add_argument("filename")

args = parser.parse_args()

if args.filename.endswith(".npy"):
    bark_spectrum = numpy.load(args.filename)
else:
    bark_spectrum = numpy.loadtxt(args.filename)

x = bark_spectrum.shape[0]
y = bark_spectrum.shape[1]
Y = numpy.arange(0, y / 100, 0.01)
X = numpy.arange(0, x / 100, 0.01)
c = plt.pcolormesh(X, Y, bark_spectrum.T, shading='nearest')

plt.colorbar(c)
plt.ylabel('Frequency [KHz]')
plt.xlabel('Time [sec]')
plt.show()

max=numpy.max(bark_spectrum)
min=numpy.min(bark_spectrum)
print("max:%le"%max)
print("min:%le"%min)
